package com.wss.lsl.acm.p2001;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.List;

public class Main {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<String> input = new LinkedList<String>();
		String word = null;
		while (true) {
			word = br.readLine();
			if (word == null || word.length() == 0) {
				break;
			}
			input.add(word.toString());
		}

		List<String> output = calc(input);
		for (int i = 0, length = input.size(); i < length; i++) {
			System.out.println(input.get(i) + " " + output.get(i));
		}

	}

	public static List<String> calc(List<String> input) {

		List<String> output = new LinkedList<String>();
		String prefix = null;
		for (String word : input) {
			prefix = String.valueOf(word.charAt(0));
			for (String word2 : input) {
				if (!word.equals(word2)) {
					for (int i = prefix.length(), length = word.length(); i < length; i++) {
						if (word2.startsWith(prefix)) {
							prefix = prefix.concat(String.valueOf(word
									.charAt(i)));
						} else {
							break;
						}
					}
					if (prefix.length() == word.length()) {
						break;
					}
				}
			}
			output.add(prefix);
		}

		return output;
	}

}
